package com.macro.mall.portal.controller;

import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.PmsComment;
import com.macro.mall.portal.domain.PmsPortalProductDetail;
import com.macro.mall.portal.service.PmsPortalCommentService;
import com.macro.mall.portal.service.PmsPortalProductService;
import com.macro.mall.portal.vo.PmsCommentAndCommentReplayVO;
import com.macro.mall.portal.vo.PmsCommentReplayVO;
import com.macro.mall.portal.vo.PmsCommentVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@Api(tags = "PmsPortalCommentController", description = "商品评价管理")
@RequestMapping("/comment")
public class PmsPortalCommentController {
    @Autowired
    private PmsPortalCommentService pmsPortalCommentService;
    @ApiOperation(value = "商品评价")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult add(@RequestBody PmsCommentVO pmsCommentVO){
        System.out.println(pmsCommentVO);
       pmsPortalCommentService.add(pmsCommentVO);
            return CommonResult.success(null,"评价成功");
    }
    @ApiOperation(value = "根据商品ID查询评价")
    @RequestMapping(value = "/getByProductId", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<List<PmsCommentAndCommentReplayVO>> listCommentAndCommentReplayGetByProductId(Long productId,@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                                                                                      @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum){
        return CommonResult.success(pmsPortalCommentService.listCommentAndCommentReplayGetByProductId(productId,pageSize,pageNum));
    }
    @ApiOperation(value = "根据商品ID查询评价")
    @RequestMapping(value = "/listByMenberId", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<List<PmsCommentAndCommentReplayVO>> listByMenberId(@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                                                                                      @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum){
        return CommonResult.success(pmsPortalCommentService.listByMenberId(pageSize,pageNum));
    }
    @ApiOperation(value = "根据评价ID批量删除评价")
    @RequestMapping(value = "/getById", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult delById(@RequestParam("ids") List<Long> ids){
        pmsPortalCommentService.delById(ids);
        return CommonResult.success("删除成功");
    }

    @ApiOperation(value = "根据评价ID查询评价")
    @RequestMapping(value = "/getById", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<PmsCommentAndCommentReplayVO> getById(Long id){
        return CommonResult.success(pmsPortalCommentService.getById(id));
    }
    @ApiOperation(value = "根据评价ID和会员ID查询评价")
    @RequestMapping(value = "/getByIdAndMenberId", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<PmsComment> getByIdAndMenberId(Long id){
        return CommonResult.success(pmsPortalCommentService.getByIdAndMenberId(id));
    }
    @ApiOperation(value = "评价回复")
    @RequestMapping(value = "/addReplay", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult addReplay(@RequestBody PmsCommentReplayVO pmsCommentReplayVO){
        pmsPortalCommentService.addReplay(pmsCommentReplayVO);
        return CommonResult.success(null,"回复成功");
    }
}
